﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineTestBLL;
using OnlineTestModel;

namespace OnlineTestUI.BackManager
{
    public partial class CreatDB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //DB db = new DB();//题目数据库
            //PartDB pdb = new PartDB();
        }
    }

    public class PartDB
    {
        public PartDB()
        {
            PartsBLL pb = new PartsBLL();
            for (int i = 1; i <= 10; i++)
            {
                Parts chapter = new Parts();
                chapter.ParentId = null;
                chapter.PartName = "这是第"+i+"章";
                chapter.PartNumber = i*100;
                chapter.IsImportant = false;
                chapter.CourseId = 1;
                int result=pb.Add(chapter);
                if (result > 0)
                {
                    for (int n = 1; n <= 14; n++)
                    {
                        Parts p = new Parts();
                        p.PartName = "这是第" + i + "章的第" + n + "节";
                        p.PartNumber = i * 100 + n;
                        p.IsImportant = false;
                        p.CourseId = 1;
                        p.ParentId = result;
                        pb.Add(p);
                    }
                }
            }
        }
    }

    public class DB
    {
        /// <summary>
        /// 题库
        /// </summary>
        public List<Questions> QuestionsDB;

        public DB()
        {
            QuestionsDB = new List<Questions>();
            Questions model;
            Random rand = new Random();
            QuestionsBLL qb = new QuestionsBLL();
            QuestionItemsBLL qib = new QuestionItemsBLL();
            double Points;
            for (int i = 1; i <= 4000; i++)
            {
                model = new Questions();
                model.QuestionName = "这是第" + i + "题";
                model.VersionNumber = 1;
                //试题难度系数取0.3到1之间的随机值
                model.PreDifficult = (rand.Next(30, 100) * 0.01).ToString();
                model.TrueDifficult = model.PreDifficult;
                model.Chapter = rand.Next(1, 10).ToString();
                model.Part = rand.Next(1, 14).ToString();
                model.CourseId = 1;
                model.Status = 1;
                model.PartitionDegree = "0";
                model.CorrectCount = 0;
                model.TotalCount = 0;
                model.ParentId = 0;
                //单选题
                if (i < 1001)
                {
                    model.QuestionTypeId = 1;
                    model.BlankLine = 0;
                    model.CorrectAnswer = "A";
                }

                //填空题
                if (i > 1000 && i < 2001)
                {
                    model.QuestionTypeId = 2;
                    model.BlankLine = 0;
                    model.CorrectAnswer = "这是第" + i + "题的正确答案";
                }

                //判断题
                if (i > 2000 && i < 3001)
                {
                    model.QuestionTypeId = 3;
                    model.BlankLine = 0;
                    model.CorrectAnswer = "true";
                }

                //简答题
                if (i > 3000 && i < 4001)
                {
                    model.QuestionTypeId = 4;
                    model.BlankLine = rand.Next(5, 7);
                    model.CorrectAnswer = "这是第" + i + "题的正确答案";
                }

                int result =qb.Add(model);
                if (result > 0)
                {
                    if (model.QuestionTypeId == 1)
                    {
                        for (int n = 0; n < 4; n++)
                        {
                            QuestionItems qi = new QuestionItems();
                            qi.QuestionId = result;
                            qi.ItemName = "这是第"+i+"题的第"+n+"个选项";
                            qi.ItemGrade = n;
                            qib.Add(qi);
                        }
                    }
                }
            }
        }

    }
}